/* model */
import { 
  BaseSelectUserLoadingKeyEnum,
  BaseSelectUserStoreLoadingMapDataType,
  BaseSelectUserStoreLoadingMapType,
  BaseSelectUserVuexPropertyEnum 
} from '@src/component/common/BaseSelectUser/store'
/* store */
import { useBaseSelectUserStore } from '@src/component/common/BaseSelectUser/store/hooks/base'
/* vue */
import { computed } from 'vue'
/** 
 * @description 选人控件 加载状态
*/
function useBaseSelectUserStoreLoadingMap() {
  
  const store = useBaseSelectUserStore()
  
  const loadingMap = computed(() => store.state.loadingMap)
  
  // 部门加载状态
  const departmentLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.Department]
  })
  
  // 部门成员加载状态
  const departmentUserLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.DepartmentUser]
  })
  
  // 角色加载状态
  const roleLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.Role]
  })
  
  // 角色成员加载状态
  const roleUserLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.RoleUser]
  })
  
  // 服务商加载状态
  const serviceProviderLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.ServiceProvider]
  })
  
  // 服务商成员加载状态
  const serviceProviderUserLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.ServiceProviderUser]
  })
  
  // 项目组加载状态
  const projectTeamLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.ProjectTeam]
  })

  // 项目组成员加载状态
  const projectTeamUserLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.ProjectTeamUser]
  })
  
  // 搜索加载状态
  const searchLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.Search]
  })
  
  // tab 选项卡 加载状态
  const tabLoading = computed(() => {
    return loadingMap.value[BaseSelectUserLoadingKeyEnum.Tab]
  })
  
  const setLoadingMap = (value: BaseSelectUserStoreLoadingMapType) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetUserCountMap, value)
  }
  
  const setDepartmentLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapDepartmentLoading, value)
  }
  
  const setDepartmentUserLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapDepartmentUserLoading, value)
  }
  
  const setRoleLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapRoleLoading, value)
  }
  
  const setRoleUserLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapRoleUserLoading, value)
  }
  
  const setServiceProviderLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapServiceProviderLoading, value)
  }
  
  const setServiceProviderUserLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapServiceProviderUserLoading, value)
  }
  
  const setProjectTeamLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapProjectTeamLoading, value)
  }

  const setProjectTeamUserLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapProjectTeamUserLoading, value)
  }

  const setSearchLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapSearchLoading, value)
  }
  
  const setTabLoading = (value: BaseSelectUserStoreLoadingMapDataType = true) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetLoadingMapTabLoading, value)
  }
  
  // 清除部门加载状态
  const clearDepartmentLoading = () => setDepartmentLoading(false)
  // 清除部门成员加载状态
  const clearDepartmentUserLoading = () => setDepartmentUserLoading(false)
  // 清除角色加载状态
  const clearRoleLoading = () => setRoleLoading(false)
  // 清除角色成员加载状态
  const clearRoleUserLoading = () => setRoleUserLoading(false)
  // 清除服务商加载状态
  const clearServiceProviderLoading = () => setServiceProviderLoading(false)
  // 清除服务商成员加载状态 
  const clearServiceProviderUserLoading = () => setServiceProviderUserLoading(false)
  // 清除项目加载状态
  const clearProjectTeamLoading = () => setProjectTeamLoading(false)
  // 清除项目成员加载状态
  const clearProjectTeamUserLoading = () => setProjectTeamUserLoading(false)
  // 清除搜索加载状态
  const clearSearchLoading = () => setSearchLoading(false)
  // 清除tab 选项卡 加载状态
  const clearTabLoading = () => setTabLoading(false)
  
  return {
    loadingMap,
    departmentLoading,
    departmentUserLoading,
    roleLoading,
    roleUserLoading,
    serviceProviderLoading,
    serviceProviderUserLoading,
    projectTeamLoading,
    projectTeamUserLoading,
    searchLoading,
    tabLoading,
    
    setLoadingMap,
    
    setDepartmentLoading,
    setDepartmentUserLoading,
    setRoleLoading,
    setServiceProviderLoading,
    setSearchLoading,
    setTabLoading,
    setRoleUserLoading,
    setServiceProviderUserLoading,
    setProjectTeamLoading,
    setProjectTeamUserLoading,
    
    clearDepartmentLoading,
    clearDepartmentUserLoading,
    clearRoleLoading,
    clearServiceProviderLoading,
    clearSearchLoading,
    clearTabLoading,
    clearRoleUserLoading,
    clearServiceProviderUserLoading,
    clearProjectTeamLoading,
    clearProjectTeamUserLoading
  }
}

export {
  useBaseSelectUserStoreLoadingMap
}
